package com.hws.leetcode.Day_01_01;

import java.util.Arrays;

/**
 * ClassName:leetcode_2022
 * Package:com.hws.leetcode.Day_01_01
 * Description:
 *
 * @ date:2022/1/1 14:46
 * @ author:hws
 */
public class leetcode_2022 {

    public int[][] construct2DArray(int[] original, int m, int n) {
        if (m * n != original.length){
            return new int[][]{};
        }
        int[][] result = new int[m][n];
        int index = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                result[i][j] = original[index++];
            }
        }
        return result;
    }

    public static void main(String[] args) {
        leetcode_2022 lc = new leetcode_2022();
        int[] nums = {1,2,3,4};
        System.out.println(Arrays.deepToString(lc.construct2DArray(nums, 2, 2)));
    }
}
